<?php
class studentAccountModel extends model
{
    public function delete($id, $table = null)
    {
        return $this->dao->update('student_charge_log')->set('del=1')->where('student_id')->eq($id)->exec();
    }
    public function getList($pager = null)
    {
        return $this->dao
            ->select('a.id, a.student, b.remainder, b.account_type,c.name as account_type_name')
            ->from('student')->alias('a')
            ->leftJoin('student_account')->alias('b')
            ->on("a.id=b.student_id")
            ->leftJoin('account_class')->alias('c')
            ->on('b.account_type=c.type')
            ->where('a.del')->eq('0')->andWhere('b.del')->eq('0')
            ->orderBy('id asc')
            ->page($pager)->fetchAll();
    }
    public function getById($id,$accountType)
    {
        return $this->dao->select("id, money,date")
            ->from('student_charge_log')
            ->where("student_id")->eq($id)
            ->andWhere("account_type")->eq($accountType)
            ->andWhere('del')->eq('0')
            ->orderBy('id asc')
            ->fetchAll();
    }
    public function create()
    {
        $account = fixer::input('post')
            ->specialchars('student_id, account_type')
            ->add('date', date('Y-m-d H:i:s'))
            ->get();
        $this->dao
            ->insert('student_account')
            ->data($account)
            ->batchCheck('student_id', 'notempty')
            ->exec();
    }
}